import Layout from '@c/Layout/index.vue'
import { createRouter, createWebHistory } from 'vue-router'
import guard from './guard'
const defaultRoutes = [
  {
    path: '/',
    name: '',
    hidden: true,
    redirect: '/dashboard',
  },
  {
    path: '/login',
    name: 'login',
    hidden: true,
    component: () => import('@p/login/index.vue'),
  },
  {
    path: '/404',
    name: '404',
    hidden: true,
    component: () => import('@p/404/index.vue'),
  },
]
export const routes = [
  {
    path: '/dashboard',
    component: Layout,
    redirect: '/dashboard/first',
    children: [
      {
        path: 'first',
        name: 'first',
        component: () => import('@p/test1/index.vue'),
        meta: {
          title: '首页',
          icon: 'icon-shouye',
          fix: true,
        },
      },
    ],
  },
  {
    path: '/profile',
    component: Layout,
    redirect: '/profile/index',
    hidden: true,
    children: [
      {
        path: 'index',
        name: 'index',
        component: () => import('@p/profile/index.vue'),
        meta: { title: '个人中心' },
      },
    ],
  },
  {
    path: '/cost',
    component: Layout,
    redirect: '/cost/costMoneyType',
    name: '账单管理',
    meta: { title: '账单管理', icon: 'icon-xitong-caidanguanli' },
    children: [
      {
        path: 'costMoneyType',
        name: 'costMoneyType',
        component: () => import('@p/test1/index.vue'),
        meta: { title: '账单类型图标', icon: 'icon-shouye', roles: ['admin'] },
      },
      {
        path: 'costList',
        name: 'costList',
        component: () => import('@p/test2/index.vue'),
        meta: { title: '账单记录', icon: 'icon-shezhi' },
      },
    ],
  },
  { path: '/:pathMatch(.*)', redirect: '/404', hidden: true },
]

const router = createRouter({
  history: createWebHistory(),
  routes: defaultRoutes,
})
router.beforeEach(guard.beforeEach)
router.afterEach(guard.afterEach)
export default router
